const common = require('./common')

const puppeteer = require('puppeteer');

(async () => {
    const browser = await puppeteer.launch({
      headless: false
    } );
    const page = await browser.newPage();
    await page.goto('http://service.js.10086.cn/login.html?url=http://service.js.10086.cn/CZKCZNEW.html?t=1567068729463');

    while(true){
        await common.timeout(3000 + new Date().getSeconds());
        let url = page.url();
        console.log(url);
        if(page.target().url().indexOf("CZKCZNEW.html")>-1){
            page.type('#payCard-password' , '111111111111111');

            // Select the #svg img element and save the screenshot.
  const svgImage = await page.$('#czvcimg');
  await svgImage.screenshot({
    path: 'logo-screenshot.png',
    omitBackground: true,
  });

        }
        
    }
    // await browser.close();
  })();